# -- coding: utf-8 --
# @File : Mysql_DB.py
# @Time : 2024/8/19
# @Author : RLH
# 功能描述: 操作mysql数据库
import pymysql
from core.Operation_DB.OperateDBInterface import OperateDBInterface
from core.Base_Tools_modlue import BaseTools_Cls
config_file = "/conf/config.ini"

class MysqlDatabase(OperateDBInterface):
    def __init__(self, host=None, port=None, user=None, password=None, db=None):
        if host is None:
            host = BaseTools_Cls.read_config(config_file, "mysql", "host")
        if port is None:
            port = int(BaseTools_Cls.read_config(config_file,  "mysql", "port"))
        if user is None:
            user = BaseTools_Cls.read_config(config_file, "mysql", "user")
        if password is None:
            password = BaseTools_Cls.read_config(config_file, "mysql", "password")
        if db is None:
            db = BaseTools_Cls.read_config(config_file,"mysql", "db")
        self.connection = pymysql.connect(host=host, port=port, user=user, password=password, db=db, charset='utf8mb4',
                                          autocommit=True)
